package org.linlinjava.litemall.db.service;

import java.util.List;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.yulichang.base.MPJBaseServiceImpl;
import org.linlinjava.litemall.db.dao.LitemallGoodsRegionMapper;
import org.linlinjava.litemall.db.domain.LitemallGoodsRegion;
import org.linlinjava.litemall.db.domain.LitemallGoodsRegionExample;
import org.springframework.stereotype.Service;

@Service
public class LitemallGoodsRegionService extends MPJBaseServiceImpl<LitemallGoodsRegionMapper,LitemallGoodsRegion> {
	
    @Resource
    private LitemallGoodsRegionMapper GoodsRegionMapper;



    public List<LitemallGoodsRegion> queryByGid(Integer goodsId) {
        LitemallGoodsRegionExample example = new LitemallGoodsRegionExample();
        example.or().andGoodsIdEqualTo(goodsId);
        return GoodsRegionMapper.selectByExample(example);
    }

    public List<LitemallGoodsRegion> queryByPid(Integer packageId) {
        LitemallGoodsRegionExample example = new LitemallGoodsRegionExample();
        example.or().andPackageIdEqualTo(packageId);
        return GoodsRegionMapper.selectByExample(example);
    }

    public LitemallGoodsRegion findById(Integer id) {
        return GoodsRegionMapper.selectByPrimaryKey(id);
    }

    public void deleteByGid(Integer gid) {
        LitemallGoodsRegionExample example = new LitemallGoodsRegionExample();
        example.or().andGoodsIdEqualTo(gid);
        GoodsRegionMapper.deleteByExample(example);
    }

    public void deleteByPid(Integer pid) {
        LitemallGoodsRegionExample example = new LitemallGoodsRegionExample();
        example.or().andPackageIdEqualTo(pid);
        GoodsRegionMapper.deleteByExample(example);
    }

    public void add(LitemallGoodsRegion goodsRegion) {
        GoodsRegionMapper.insertSelective(goodsRegion);
    }
    
    public void update(LitemallGoodsRegion goodsRegion) {
    	GoodsRegionMapper.updateByPrimaryKey(goodsRegion);
    }
    
    public LitemallGoodsRegion findByGidAndCityId(Integer goodsId, Integer cityId) {
        LitemallGoodsRegionExample example = new LitemallGoodsRegionExample();
        example.or().andGoodsIdEqualTo(goodsId).andCityIdEqualTo(cityId);
        return GoodsRegionMapper.selectOneByExample(example);
    }

    public LitemallGoodsRegion findByPackageIdAndCityId(Integer packageId, Integer cityId) {
        return GoodsRegionMapper.selectOne(Wrappers.lambdaQuery(LitemallGoodsRegion.class)
                .eq(LitemallGoodsRegion::getPackageId,packageId).eq(LitemallGoodsRegion::getCityId,cityId));
    }

    public List<LitemallGoodsRegion> selectByCityId(Integer cityId) {
        return GoodsRegionMapper.selectList(Wrappers.lambdaQuery(LitemallGoodsRegion.class)
                .eq(LitemallGoodsRegion::getCityId,cityId));
    }

    public List<LitemallGoodsRegion> selectByCityIdGoods(Integer cityId) {
        return GoodsRegionMapper.selectList(Wrappers.lambdaQuery(LitemallGoodsRegion.class)
                .isNotNull(LitemallGoodsRegion::getGoodsId)
                .eq(LitemallGoodsRegion::getCityId,cityId));
    }

}
